<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>文章管理</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <link rel="stylesheet" href="/plugins/ueditor/themes/default/css/ueditor.css" />
    <link rel="stylesheet" href="/plugins/ueditor/themes/iframe.css" />
    <link href="/css/lanai-ui.css" rel="stylesheet" />
	<link rel="stylesheet" href="/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script src="/plugins/layer/layer.js"></script>
	<script type="text/javascript" src="/plugins/ztree/js/jquery.ztree.core.js"></script>
	<script src="/js/lanai-ui.js"></script>
    <script type="text/javascript">
     	window.UEDITOR_HOME_URL = "/plugins/ueditor/";
    </script>
    <script type="text/javascript" charset="utf-8" src="/plugins/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="/plugins/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>
  
</head>
<body>
<div style="margin-left: 16px;">
    <button style="margin-top: 4px;margin-bottom: 4px;" type="button" class="btn btn-primary" onclick="showDeptZtree()"><i class="fa fa-plus"></i>&nbsp;选择文章所属站点菜单</button>
    <span id="showName" th:text="${article.menuName}"></span></br>
   	 文章标题:&nbsp;&nbsp;<input id="title" type="text" th:value="${article.title}" style="width:180px;height:30px; border-radius:8px;border:1px solid #8968CD; margin-bottom: 4px;">
    <script id="editor" type="text/plain" style="width:99%;height:350px;"></script>
    <input id="menuid" type="hidden" th:value="${article.menuId}">
     <input id="articleId" type="hidden" th:value="${article.articleId}">
    <input id="tempcontent" type="hidden" th:value="${article.textHtml}">
</div>

<div id="btns" style="width:98%;margin-top: 4px">
    <div style="float: right;">   
    	<button type="button" class="btn btn-primary" onclick="ue.setContent('')">重&nbsp;&nbsp;&nbsp;&nbsp;置</button>     
        <button type="button" class="btn btn-primary" onclick="getContentTxt()">提&nbsp;&nbsp;&nbsp;&nbsp;交</button>
    	<button type="button" class="btn btn-primary" onclick="location.href='javascript:history.back(-1);'">返&nbsp;&nbsp;&nbsp;&nbsp;回</button>
    </div>
</div>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    setTimeout(function(){
    	var htmlstr = $("#tempcontent").val();
  		UE.getEditor('editor').execCommand("insertHtml", htmlstr);
  	},500);
    
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }
    
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
        UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
        alert(arr.join("\n"));
    }

    //获取纯文本 ===>保存文章
    function getContentTxt() {
        var arr = [];
        //arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        //arr.push("编辑器的纯文本内容为：");
        arr.push(UE.getEditor('editor').getContentTxt());
        var text = arr.join("\n");//纯文本内容
        var menuId = $("#menuid").val();//所属菜单id
        var title = $("#title").val();//标题
        var textHtml = ue.getAllHtml();//html内容
        var articleId=  $("#articleId").val();//文章id
        if(articleId>0){
        	var url = "/tgqmdj/updateArticle";//修改
        }else{
        	var url = "/tgqmdj/insertText";	  //新增
        }
        $.ajax({
	    	url:url,
	    	type:"post",
	    	dataType:"json",
	    	data:{"menuId":menuId,"text":text,"title":title,"textHtml":textHtml,"articleId":articleId,"menuId":menuId},
			success:function(ret){
				if(ret.code != 0){
					layer.alert('操作成功', {icon: 6});
					ue.setContent("");
					$("#showName").text("");
					$("#title").val("");
					 
					
				}else{
					layer.alert('操作失败', {icon: 7});
				}
			},
			error:function(e){
				alert("e:"+e);
			}
        });
        
    }
    
    //判断是否有内容
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为：");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("\n"));
    }
 //选择文章所属站点菜单 
    function showDeptZtree(){
    	
    	layer.open({
    		  type: 1,
    		  skin: 'layui-layer-demo', //样式类名
    		  area: ['180px', '250px'], //宽高
    		  closeBtn: 1, //不显示关闭按钮
    		  anim: 2,
    		  shadeClose: false, //开启遮罩关闭
    		  btn: ['确定'],
    		  content:'<ul id="deptztree" class="ztree"></ul>',
    		  
    	});
    	loadDeptData();
    	
    } 

    function loadDeptData(){
    	
    	    var setting = {
    			data: {
    				simpleData: {
    					enable: true
    				}
    			},
    			callback: {
    				onClick: zTreeOnClick
    			}
    		};
    		
    	    $.ajax({
    	    	url:"/tgqmdj/queryMenu",
    	    	type:"post",
    	    	dataType:"json",
    	    	data:{},
    			success:function(ret){
    				var tempdata = ret.data;
    				$.fn.zTree.init($("#deptztree"), setting, tempdata);
    				var treeObj = $.fn.zTree.getZTreeObj("deptztree");
    	            var nodes = treeObj.getNodes();
    	            for (var i = 0; i < nodes.length; i++) { //设置节点展开
    	                treeObj.expandNode(nodes[i], true, false, true);
    	            }
    			},
    			error:function(e){
    				alert("e:"+e);
    			}
    	    	
    	    	
    	    });		
    }

    function zTreeOnClick(event, treeId, treeNode) {
       //alert(treeNode.id + ",treeId " +treeId+ "======="+treeNode.name);
       $("#menuid").val(treeNode.id);
       $("#showName").text("当前选择: "+treeNode.name);     
    }
    

</script>
</body>
</html>